from django.core.validators import RegexValidator
from django.shortcuts import render
from app01 import models
# Create your views here.

from django import forms

class RegisterForm(forms.ModelForm):
    mobile_phone = forms.CharField(label='手机号', validators=[RegexValidator(r'\d{3}-\d{8}|\d{4}-\{7,8}', '手机格式错误')])
    password = forms.CharField(label='密码', widget=forms.PasswordInput)
    confirm_password = forms.CharField(label='重复密码', widget=forms.PasswordInput)
    class Meta:
        model = models.UserInfo
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name,field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'
            field.widget.attrs['placeholder'] = '请输入{}'.format(field.label)

def register(request):
    form = RegisterForm()
    return render(request, 'app01/register.html', locals())